Program a
implicit none

real*8 eps,x0,x1,resu
integer*2 iter
eps = 1.E-6
print *,'Input 2 tebakan awal'
write(*,"('    X0 = ')",advance='no')
read *, x0
write(*,"('    X1 = ')",advance='no')
read *, x1
call secant (eps,x0,x1,resu,iter)
print *,resu
pause
end

subroutine secant (eps,a,b,hasil,count)
    implicit none    
    real*8 eps,a,b,hasil,x0,x1,y0,y1,fungsi,c
    integer*2 count
	integer i
    x0 = a
    x1 = b
    count = 0
    hasil = 0
    y0 = fungsi (x0)
    y1 = fungsi (x1)
    c = ((y0*x1)-(y1*x0))/(y0-y1)
    do while ((abs(c-x0) > eps) .AND. (count < 100))
        count = count + 1
        y0 = fungsi (x0)
        y1 = fungsi (x1)               
        if ((y0-y1) .EQ. 0.0D0) then
        print*, 'Fail'
        exit
        end if       
        c = ((y0*x1)-(y1*x0))/(y0-y1)       
        if (abs(fungsi(c)) < eps) then
        hasil = c
        exit
        end if
		print*, count,'     ',x0,'     ',x1,'     ',c,'     ',abs(c-x0)
        x0 = x1
        x1 = c
    end do
    end subroutine secant
    
real*8 function fungsi(x)
implicit none
INCLUDE <EXCEPTN.INS>
EXTERNAL AllHandler
real*8 x
integer OldHandler, AllHandler
OldHandler = TRAP_EXCEPTION@(ALL_EXCEPTIONS,AllHandler)
fungsi = (1.4E-5*(x**15)) + (1.15E-5*(x**2))
end

integer function AllHandler()
    INCLUDE <EXCEPTN.INS>
    print *, "Pencarian nilai gagal"
    AllHandler = NONCONTINUABLE_EXCEPTION
end